﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sherwood.SignOn.Server.Models.Services;
using Sherwood.SignOn.Server.Controllers;

namespace Sherwood.SignOn.Server.Tests.UserAccountTests
{
    [TestClass]
    public class EnableDisableUserAccountTests
    {

        [TestMethod]
        public void EnableUserAccountTest()
        {
            //Assemble
            IUserAccount user1 = TestHelper.RegisterValidDummyUser("NewUser", "someone@somewhere.sherwood.local", "John", "Brown");
            IUserAccount user2 = TestHelper.RegisterValidDummyUser("AnotherUser", "user2@somewhereelse.sherwood.local", "Joe", "Bloggs");
            IUserAccount user3 = TestHelper.RegisterValidDummyUser("YetAnother", "humpty@somewhereelse.sherwood.local", "Humpty", "van Dumpty");
            IUserAccount user4 = TestHelper.RegisterValidDummyUser("YetAnother2", "humpty2@somewhereelse.sherwood.local", "Humpty2", "van Dumpty2");

            //Act
            user2.SetEnabled(false); //test disabling
            user3.SetEnabled(false); //test disabling and then enabling
            user3.SetEnabled(true);
            user4.SetEnabled(true); //test enabling an already enabled user
            user1 = Data.UserAccounts.GetUserAccount(user1.Id);
            user2 = Data.UserAccounts.GetUserAccount(user2.Id);
            user3 = Data.UserAccounts.GetUserAccount(user3.Id);
            user4 = Data.UserAccounts.GetUserAccount(user4.Id);

            
            //Assert
            Assert.IsTrue(user1.IsEnabled, "User should still be enabled (not affected by other accounts being disabled)");
            Assert.IsFalse(user2.IsEnabled, "User #2 should be disabled.");
            Assert.IsTrue(user3.IsEnabled, "User #3 should be enabled.");
            Assert.IsTrue(user4.IsEnabled, "User #4 should be enabled.");

        }




        [TestMethod]
        public void EnableUserAccountUsingController()
        {
            //Assemble
            IUserAccount user1 = TestHelper.RegisterValidDummyUser("NewUser", "someone@somewhere.sherwood.local", "John", "Brown");
            IUserAccount user2 = TestHelper.RegisterValidDummyUser("AnotherUser", "user2@somewhereelse.sherwood.local", "Joe", "Bloggs");
            IUserAccount user3 = TestHelper.RegisterValidDummyUser("YetAnother", "humpty@somewhereelse.sherwood.local", "Humpty", "van Dumpty");
            IUserAccount user4 = TestHelper.RegisterValidDummyUser("YetAnother2", "humpty2@somewhereelse.sherwood.local", "Humpty2", "van Dumpty2");

            //Act
            AdministrationController controller = new AdministrationController();
            controller.EnableUserAccount(user2.Id, false);//test disabling
            controller.EnableUserAccount(user3.Id, false); //test disabling and then enabling
            controller.EnableUserAccount(user3.Id, true);
            controller.EnableUserAccount(user4.Id, true); //test enabling an already enabled user
            user1 = Data.UserAccounts.GetUserAccount(user1.Id);
            user2 = Data.UserAccounts.GetUserAccount(user2.Id);
            user3 = Data.UserAccounts.GetUserAccount(user3.Id);
            user4 = Data.UserAccounts.GetUserAccount(user4.Id);


            //Assert
            Assert.IsTrue(user1.IsEnabled, "User should still be enabled (not affected by other accounts being disabled)");
            Assert.IsFalse(user2.IsEnabled, "User #2 should be disabled.");
            Assert.IsTrue(user3.IsEnabled, "User #3 should be enabled.");
            Assert.IsTrue(user4.IsEnabled, "User #4 should be enabled.");
        }

     
    }
}
